package com.yesep.learn.design.common.util;

import com.yesep.learn.design.common.pojo.*;
import com.yesep.learn.design.creational.builder.*;
import com.yesep.learn.design.creational.factory.*;

import java.util.*;
import java.util.stream.*;

public class DemoUtil {
    public static Dog createDog() {
        IAnimalFactoryMethod<Dog> factory = new DogFactory();
        return factory.createAnimal("旺财");
    }

    public static Cat createCat() {
        IAnimalFactoryMethod<Cat> factory = new CatFactory();
        return factory.createAnimal("汤姆");
    }

    public static Bird createBird() {
        IAnimalFactoryMethod<Bird> factory = new BirdFactory();
        return factory.createAnimal("伍迪");
    }

    public static Bee createBee() {
        IAnimalFactoryMethod<Bee> factory = new BeeFactory();
        return factory.createAnimal("园丁");
    }

    public static Computer createHPComputer() {
        Director hpDirector = new Director(new HPComputerBuilder());
        return hpDirector.constructComputer();
    }

    public static Computer createDELLComputer() {
        Director dellDirector = new Director(new DELLComputerBuilder());
        return dellDirector.constructComputer();
    }

    public static CPUComponent createCPUComponent() {
        return new CPUComponent("Intel Core i7-11700K", 8.5);
    }

    public static RAMComponent createRAMComponent() {
        return new RAMComponent("DDR4", 0.5);
    }

    public static StorageComponent createStorageComponent() {
        return new StorageComponent("NVMe SSD", 2.5);
    }


    public static AudioPlayer createAudioPlayer() {
        return new AudioPlayer();
    }

    public static VideoPlayer createVideoPlayer() {
        return new VideoPlayer();
    }


    public static List<Goods> createGoodsList() {
        List<Goods> goodsList = new ArrayList<>();
        goodsList.addAll(createGoodsList("苹果", 10, 5));
        goodsList.addAll(createGoodsList("桔子", 15, 3));
        goodsList.addAll(createGoodsList("榴莲", 29, 2));
        return goodsList;
    }

    private static List<Goods> createGoodsList(String name, int price, int count) {
        return IntStream.range(0, count).mapToObj(i -> new Goods(name, price)).collect(Collectors.toList());
    }
}
